﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace CPPEI.ETL.WebApi.ApiControllers
{
    public class UpdateController : ApiController
    {
        public UpdateController()
        {
            CPPEI.WebApi.Intergration.Config.Init();
        }

        [HttpPost]
        public ServiceResult DtSrc(DataContracts.Update.DtSrcParams @params)
        {
            return new Domain.Services.DtSerService().UpdateDtSrc(CPPEI.WebApi.Intergration.Config.AuthProvider.GetUserId(),
                @params.Id,
                @params.Name);
        }

        [HttpPost]
        public ServiceResult DtSrcCols(DataContracts.Update.DtSrcColsParams @params)
        {
            return new Domain.Services.DtSerService().UpdateDataSourceColumns(CPPEI.WebApi.Intergration.Config.AuthProvider.GetUserId(),
                @params.DtSerId,
                @params.DtSrcId,
                @params.DtSrcName,
                @params.Cols);
        }

        /// <summary>
        /// 修改数据源的列和返回结果
        /// </summary>
        /// <param name="params"></param>
        /// <returns></returns>
        [HttpPost]
        public ServiceResult DtSrcParamsCols(DataContracts.Update.DtSrcParamsColsParams @params)
        {
            return new Domain.Services.DtSerService().UpdateDataSourceParamsAndColumns(CPPEI.WebApi.Intergration.Config.AuthProvider.GetUserId(),
                @params.DtSerId,
                @params.DtSrcId,
                @params.DtSrcName,
                @params.DtSrcValue,
                @params.Params,
                @params.Cols);
        }

        [HttpPost]
        public ServiceResult TaskCategory(DataContracts.Update.TaskCategoryParams @params)
        {
            return new Domain.Services.DtSerService().UpdateTaskCategory(CPPEI.WebApi.Intergration.Config.AuthProvider.GetUserId(),
                @params.Id,
                @params.Code,
                @params.Name);
        }
    }
}
